import { Book } from '@app/database/schemas/book.schema';
import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UseGuards,
  Query,
} from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
import { BooksService } from './books.service';

@UseGuards(AuthGuard('jwt'))
@ApiBearerAuth()
@ApiTags('后台图书模块')
@Controller('/admin/books')
export class BooksController {
  constructor(private readonly booksService: BooksService) {}

  @ApiOperation({ summary: '创建图书' })
  @Post()
  create(@Body() book: Book) {
    return this.booksService.create(book);
  }

  @ApiOperation({ summary: '图书列表' })
  @Get()
  findAll(@Query() query: any) {
    return this.booksService.findAll(query);
  }

  @ApiOperation({ summary: '查询图书' })
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.booksService.findOne(id);
  }

  @ApiOperation({ summary: '修改图书' })
  @Patch(':id')
  update(@Param('id') id: string, @Body() book: Book) {
    return this.booksService.update(id, book);
  }

  @ApiOperation({ summary: '删除图书' })
  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.booksService.remove(id);
  }

  @ApiOperation({ summary: '图书配置' })
  @Post('options')
  async bookConfigs(): Promise<any> {
    return this.booksService.option();
  }
}
